﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace TakeoutMangesDAL
{
   public class EnterpriseDAL
    {
        public static List<Enterprise> EnterpriseInfo()
        {
            string sqltr = "select * from Enterprise";
            SqlDataReader reader = DBHelper.ExecuteReader(sqltr, CommandType.Text, null);
            List<Enterprise> list = new List<Enterprise>();
            while (reader.Read())
            {
                Enterprise ep = new Enterprise
                {
                    EnterpriseID = Convert.ToInt32(reader["EnterpriseID"]),
                    EnterpriseName = reader["EnterpriseName"].ToString(),
                    EnterpriseTel = reader["EnterpriseTel"].ToString(),
                    EnterpriseAdress = reader["EnterpriseAdress"].ToString(),
                    Isdelete = Convert.ToInt32(reader["Isdelete"]),
                };
                list.Add(ep);
            }
            reader.Close();
            return list;
        }
        public static int UpdateEnterprise(int EnterpriseID)
        {
            string sqltr = "update Enterprise set Isdelete=1 where EnterpriseID=@EnterpriseID";
            SqlParameter[] paras = new SqlParameter[] {
            new SqlParameter("@EnterpriseID",EnterpriseID)
            };
            return DBHelper.ExecuteNonQuery(sqltr, paras);
        }
        public static int AddEnterprise(int EnterpriseID)
        {
            string sqltr = "update Enterprise set Isdelete=0 where EnterpriseID=@EnterpriseID";
            SqlParameter[] paras = new SqlParameter[] {
            new SqlParameter("@EnterpriseID",EnterpriseID)
            };
            return DBHelper.ExecuteNonQuery(sqltr, paras);
        }
        public static int InsertEnterprise(Enterprise ep)
        {
            string sqltr = "insert into Enterprise values(@EnterpriseName,@EnterpriseTel,@EnterpriseAdress,@Isdelete)";
            SqlParameter[] paras = new SqlParameter[] {
            new SqlParameter("@EnterpriseName",ep.EnterpriseName),
            new SqlParameter("@EnterpriseTel",ep.EnterpriseTel),
            new SqlParameter("@EnterpriseAdress",ep.EnterpriseAdress),
            new SqlParameter("@Isdelete",ep.Isdelete),
            };
            return DBHelper.ExecuteNonQuery(sqltr, paras);
        }
    }
}
